/**
 * Project of Vehicle Routing Problem with Time Windows implements 
 * some of well-known algorithms for solving VRPTW and presents new 
 * one.
 *
 * @author Michal Drobny  
 */

package logic.restrictionAdapter;

import java.util.List;

import logic.restriction.Restriction;
import logic.restriction.enumeration.ChangeCycleVariant;
import logic.restriction.enumeration.IterationType;

/**
 * Represents a simple restriction adapter for vehicle routing problem. This
 * adapter checks, if all restrictions are passed.
 * 
 * @author Michal Drobny
 * @date 25.11.2014
 */
public class SimpleRestrictionAdapter extends RestrictionAdapter {

	/**
	 * Constructor.
	 */
	public SimpleRestrictionAdapter() {
		super();
	}

	/**
	 * Constructor.
	 * 
	 * @param restrictions
	 *            The restrictions
	 */
	public SimpleRestrictionAdapter(List<Restriction> restrictions) {
		super(restrictions);
	}

	@Override
	public void iterate(IterationType type, Object... params) {
		for (Restriction restriction : getRestrictions())
			restriction.iterate(type, params);
	}

	@Override
	public boolean canIterate(IterationType type, Object... params) {
		boolean result = true;
		for (Restriction restriction : getRestrictions())
			if (!restriction.canIterate(type, params))
				result = false;
		return result;
	}

	@Override
	public void newCycle(ChangeCycleVariant type, Object... params) {
		for (Restriction restriction : getRestrictions())
			restriction.newCycle(type, params);
	}

	@Override
	public boolean canNewCycle(ChangeCycleVariant type, Object... params) {
		boolean result = true;
		for (Restriction restriction : getRestrictions())
			if (!restriction.canNewCycle(type, params))
				result = false;
		return result;
	}

	@Override
	public void reset() {
		for (Restriction restriction : getRestrictions())
			restriction.reset();
	}

	/**
	 * Adds given restriction to list of restrictions.
	 * 
	 * @param restriction
	 *            The restriction
	 */
	public void addRestriction(Restriction restriction) {
		this.restrictions.add(restriction);
	}
}